<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AsyncController
 *
 * @author yuriy
 */
class Shrinker_AsyncController extends Zend_Controller_Action{
    
    public function init() {
        $this->_helper->viewRenderer->setNoRender();
        $this->_helper->getHelper('layout')->disableLayout();
        $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
    }

    public function getshortlinkAction(){
        
        $url = $this->getRequest()->getParam("url");
        
//        if (!$url) {
//            echo "No Link!";
//            return;
//        }
      
        
        $host = Shrinker_Model_Utilities::validateURL($url);
	if (!$host) {
		$RET['error'] = 'Please enter a valid URL';
	} 
//        else if (in_array($host, $badlist)) {
//		$RET['error'] = $host . ' URLs are not allowed!';
//	} 
        else {
        $util = new Shrinker_Model_Utilities();
        $RET['message'] = $util->short($url);
        $this->_flashMessenger->addMessage('Now You\'re Logging!');
	}
        
        
        
        
        echo Zend_Json_Encoder::encode($RET);
        
    }
}

